<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>app下载地址管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/css/global.css" media="all">
    <link rel="stylesheet" href="/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/table.css"/>
    <style type="text/css">
        .searcheBottom{margin-bottom: 10px;}
        body{overflow-y: scroll;}
    </style>
</head>
<body>
<div class="admin-main">
    <blockquote class="layui-elem-quote">
        <div class="demoTable">
            <div class="layui-inline searcheBottom">
                <a data-opt="add" href="/manage/appDownload/addDl" class="layui-btn"><i class="layui-icon">&#xe608;</i>新增app下载地址</a>
            </div>
        </div>
    </blockquote>
    <span style="font-size: 16px;"><b>app下载地址列表</b></span>
    <table class="layui-hide" id="anoticeTable" lay-filter="tableFilter"></table>
</div>
<script type="text/javascript" src="/plugins/layui/layui.js"></script>
<script>
    layui.use(['jquery','table','laydate','layer','form','util'],function(){
        var $=layui.jquery,table=layui.table,laydate = layui.laydate,
            layer = layui.layer,form = layui.form,util=layui.util;

        pageInit();
        function pageInit() {
            //表格渲染
            table.render({
                elem:"#anoticeTable",
                url:"/manage/appDownload/selDlList",
                method:"post",
                cols:[[
                    {field:'id', title: 'ID', sort: true,align:'center'},
                    {field:'downloadUrl', title: '下载地址',align:'center'},
                    {field:'appType', title: '类型', align:'center',
                        templet:function(d){
                            if(d.appType=="1"){
                                return '<div class="layui-btn layui-bg-green layui-btn-xs">IOS</div>'
                            } else if(d.appType=="2"){
                                return '<div class="layui-btn layui-bg-normal layui-btn-xs">Android</div>'
                            }
                        }
                    },
                    {field:'enableFlag', title: '状态',align:'center',
                        templet: function(d){
                            if(d.enableFlag == true){
                                return '<div class="layui-btn layui-bg-green layui-btn-xs">启用</div>'
                            } else{
                                return '<div class="layui-btn layui-bg-gray layui-btn-xs">停用</div>'
                            }
                        }
                    },
                    {field:'createTime', title: '创建时间',sort: true,align:'center',
                        templet: function(d){
                            if(d.createTime!=null){
                                return util.toDateString(d.createTime, 'yyyy-MM-dd HH:mm:ss');
                            }else{
                                return "";
                            }
                        }
                    },
                    {field: 'tool', title:"操作",width:200,align:'center',
                        templet:function(d){
                            var tool = '';
                            tool+='<a href="#" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</a>';
                            if(d.enableFlag == true){
                                return tool+='<div class="layui-btn layui-btn-warm layui-btn-xs" lay-event="enable">停用</div>'
                            } else{
                                return tool+='<div class="layui-btn layui-btn-green layui-btn-xs" lay-event="enable">启用</div>'
                            }
                            return tool;
                        }
                    }
                ]],
                limits:[10,15,20,25,30],
                limit:10,
                page:true
            });
        }

        //表格监听
        table.on('tool(tableFilter)', function(obj){
            var data = obj.data;
            if (obj.event == "enable"){
                $.ajax({
                    url:"/manage/appDownload/enableDl",
                    type:"post",
                    dataType:"json",
                    data:{"id":data.id,"enableFlag":data.enableFlag,"appType":data.appType},
                    success:function(count){
                        table.reload('anoticeTable');
                    }
                })
            } else if (obj.event == "edit") {
                location.href='/manage/appDownload/editDl?id='+data.id+'';
            }
        });
    })
</script>
</body>
</html>